import pygame
import sys
import time

#Iniciar pygame
pygame.init()

#Configurar ventana
ancho = 500
alto = 400
ventana = pygame.display.set_mode((ancho, alto))
pygame.display.set_caption('Animal Crossing')

# Pintar el fondo de la ventana
ROJO = (255,0,0)
VERDE = (0,255,0)
AZUL = (0,0,255)
NEGRO = (0,0,0)
BLANCO = (255,255,255)
TURQUESA = (0,255,255)
MAGENTA = (255,0,255)

COLORES =(ROJO,VERDE,AZUL,NEGRO,BLANCO,TURQUESA,MAGENTA)

#Configurar el tipo de letra
tamanio = 48
fuente = pygame.font.SysFont(None, tamanio)

#Configurar el texto
texto = fuente.render('HOLA!!', True, MAGENTA, AZUL)
textoRect = texto.get_rect()
textoRect.centerx = ventana.get_rect().centerx
textoRect.centery = ventana.get_rect().centery
ventana.blit(texto, textoRect)



for color in COLORES:
	ventana.fill(color)
	pygame.display.update()
	time.sleep (0.005)

escena = pygame.image.load ("img/escena.jpeg")
x,y = (0,0)
ventana.blit(escena, [x,y])
pygame.display.flip()

hiha = pygame.image.load ("img/hiha.png")
x_hiha,y_hiha = (250,300)
ventana.blit(hiha, [x_hiha,y_hiha])
pygame.display.flip()

#Configurar el texto
texto = fuente.render('HOLA!!', True, MAGENTA, AZUL)
textoRect = texto.get_rect()
textoRect.centerx = ventana.get_rect().centerx
textoRect.centery = ventana.get_rect().centery
ventana.blit(texto, textoRect)



#Bucle de eventos
while True:
	for event  in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				sys.exit() 
			
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_LEFT:
					ventana.blit (escena, [x,y])
					x_hiha = x_hiha - 3
					ventana.blit(hiha, [x_hiha,y_hiha])
					pygame.display.flip()                                  

				if event.key == pygame.K_UP:
					ventana.blit (escena, [x,y])
					y_hiha = y_hiha - 3
					ventana.blit(hiha, [x_hiha,y_hiha])
					pygame.display.flip() 
                                
				if event.key == pygame.K_RIGHT:
					ventana.blit (escena, [x,y])
					x_hiha = x_hiha + 3
					ventana.blit(hiha, [x_hiha,y_hiha])
					pygame.display.flip() 
               
				if event.key == pygame.K_DOWN:
					ventana.blit (escena, [x,y])
					y_hiha = y_hiha + 3
					ventana.blit(hiha, [x_hiha,y_hiha])
					pygame.display.flip() 
